// Search模块的小仓库
import { reqGetSearchInfo } from '@/api'

const state = {
    // 仓库数据searchList初始状态
    searchList: {}
}
const mutations = {
    GETSEARCHLIST(state, searchList) {
        state.searchList = searchList
    }
}
const actions = {
        // 获取search 数据
        // 此处params为载荷
        async getSearchList({ commit }, params = {}) {
            // reqGetSearchInfo调用时至少传递一个空对象 该方法带参
            // params形参 用户派发actions第二个参数传递 至少为一个空对象 
            let result = await reqGetSearchInfo(params)
                // console.log(result)
            if (result.code == 200) {
                commit('GETSEARCHLIST', result.data)
            }
        }
    }
    // getters 简化数据
const getters = {
    // 此处state 指向当前search仓库下的state 而非根组件下
    goodsList(state) {
        return state.searchList.goodsList || []
    },
    trademarkList(state) {
        return state.searchList.trademarkList || []
    },
    attrsList(state) {
        return state.searchList.attrsList || []
    }
}

export default {
    state,
    mutations,
    actions,
    getters
}